<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <title>基本使用</title>
    <script src="../js/vue.js"></script>
</head>

<body>
    <div id="root">
        <hello></hello>
        <h2>{{msg}}</h2>
        <hr />
        <school></school>
        <hr />
        <student></student>
    </div>

    <div id="root2">
        <hello></hello>
    </div>

    <script>
        Vue.config.productionTip = false

        const school = Vue.extend({
            data() {
                return {
                    name: '尚硅谷',
                    address: '北京昌平'
                }
            },
            template: `
                <div>
                    <h2>学校名称：{{name}}</h2>
                    <h2>学校地址：{{address}}</h2>
                </div>
            `
        })

        const student = Vue.extend({
            data() {
                return {
                    name: '张三',
                    age: 20
                }
            },
            template: `
                <div>
                    <h2>学生姓名：{{name}}</h2>
                    <h2>学生年龄：{{age}}</h2>
                    <button @click="add">点我年龄加1</button>
                </div>
            `,
            methods: {
                add() {
                    this.age++;
                }
            }
        })

        //创建hello组件
        const hello = Vue.extend({
            data() {
                return {
                    msg: 'hello'
                }
            },
            template: `
                <div>
                    <h2>{{msg}}</h2>
                </div>
            `
        })

        //注册全局组件
        Vue.component('hello', hello)

        new Vue({
            el: '#root',
            data: {
                msg: 'hello!'
            },
            //注册局部组件
            components: {
                school,
                student
            }
        })

        new Vue({
            el: '#root2'
        })
    </script>
</body>

</html>